<template>
  <div>
    <div class="boxInput">
      <input class="inuputt" placeholder="1" type="text" />
      <div class="label">名称</div>
    </div>
  </div>
</template>
<script>
  import { defineComponent } from 'vue'
  import { UiMixin, RefsInjectMixin, ChartMixin } from '@ve/mixin'
  import cloneDeep from 'lodash/cloneDeep'
  export default defineComponent({
    name: 'UiAniInput',
    mixins: [UiMixin, RefsInjectMixin, ChartMixin],
    inject: {
      hasPreview: { default: false },
    },
    props: {
      info: {
        required: true,
        type: Object,
        default: function () {
          return {}
        },
      },
    },
    data() {
      return {
        infoComponent: {},
        inter: null,
        focusInput: false,
        optionBgStyle: {
          top: 50 + 'px',
          opacity: 0,
        },
        dataBgStyle: {
          top: 50 + 'px',
          opacity: 0,
        },
        text: '',
      }
    },
    watch: {
      info: {
        handler() {
          this.$nextTick(() => {
            this.infoComponent = cloneDeep(this.info)
            this.getRequestData()
            this.inter && (clearInterval(this.inter), (this.inter = null))
            if (this.info.extension.requestSet.value.loopRequest) {
              this.inter = setInterval(() => {
                this.getRequestData()
              }, this.info.extension.requestSet.value.loopTime)
            }
          })
        },
        deep: true,
      },
      set: {
        handler(val) {
          console.log(val, '-------')
          this.$forceUpdate()
        },
        deep: true,
      },
      // getSelectModule: {
      //   handler(val, oldVal) {
      //     if (!oldVal.extension) {
      //       if (pieOption[this.info.chartTypeValue]) {
      //         this.getSelectModule.extension && this.getSelectModule.extension.series && (this.getSelectModule.extension.series.isShowBtn = false)
      //       } else {
      //         this.getSelectModule.extension && this.getSelectModule.extension.series && (this.getSelectModule.extension.series.isShowBtn = true)
      //       }
      //     }
      //   },
      //   deep: true,
      // },
    },
    created() {
      this.infoComponent = cloneDeep(this.info)
    },
    mounted() {
      this.$nextTick(() => {
        this.getRequestData()
        if (this.info.extension.requestSet.value.loopRequest) {
          this.inter = setInterval(() => {
            this.getRequestData()
          }, this.info.extension.requestSet.value.loopTime)
        } else {
          this.inter && (clearInterval(this.inter), (this.inter = null))
        }
      })
    },
    deactivated() {
      console.warn('退出----------------------')
      this.inter && clearInterval(this.inter)
    },
    beforeUnmount() {
      this.inter && clearInterval(this.inter)
    },
    methods: {
      getRequestData() {
        if (this.info.extension.isDesign?.value == false) {
          this.$request(this.infoComponent.extension.requestSet.value, (res) => {
            this.infoComponent.extension.requestSet?.value.cardValue &&
              (this.text = cloneDeep(res)[0][this.infoComponent.extension.requestSet.value.cardValue])
          })
        }
      },
      mouseOver(num) {
        this.optionBgStyle = {
          top: num * 50 + 5 + 'px',
          opacity: 1,
        }
        this.dataBgStyle = {
          opacity: 0,
          top: num * 50 + 5 + 'px',
        }
      },
      choose(item) {
        this.text = item
        this.dataBgStyle = {
          opacity: 0.5,
          top: -50 + 'px',
        }
        setTimeout(() => {
          this.dataBgStyle.opacity = 0
          this.value = item
        }, 200)
      },
      mouseLeave() {
        this.optionBgStyle.opacity = 0
      },
    },
  })
</script>
<style scoped>
  .uiAniInput {
    width: 100%;
    /* overflow: hidden; */
  }
  .boxInput {
    width: 300px;
    height: 40px;
    position: relative;
    border: 2px solid rgb(55, 183, 209);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .inuputt {
    width: 94%;
    height: 82%;
    outline: none;
    border: 0;
    color: rgb(55, 183, 209);
    background: rgba(0, 0, 0, 0);
    z-index: 2;
    font-size: 12px;
  }
  .label {
    position: absolute;
    height: 82%;
    line-height: 20px;
    top: 9%;
    left: 3%;
    z-index: 1;
    font-size: 18px;
    color: rgb(55, 183, 209);
    user-select: none;
    display: flex;
    align-items: center;
    transition: top 0.3s, left 0.2s, padding 0.5s linear 0.2s, background 0s linear 0.3s;
  }
  .inuputt:focus + .label {
    top: -50%;
    left: 5%;
    padding: 0 20px;
    display: flex;
    align-items: center;
    background: #000943;
  }
  .inuputt:focus + .label::before {
    content: '';
    display: inline-block;
    position: absolute;
    width: 2px;
    height: 50%;
    background: rgb(55, 183, 209);
    left: 2%;
  }
  .inuputt:focus + .label::after {
    content: '';
    display: inline-block;
    position: absolute;
    width: 2px;
    height: 50%;
    background: rgb(55, 183, 209);
    right: 2%;
  }
  .inuputt:not(:placeholder-shown) + .label {
    top: -50%;
    left: 5%;
    padding: 0 20px;
    display: flex;
    align-items: center;
    background: #000;
  }
  .inuputt:not(:placeholder-shown) + .label::before {
    content: '';
    display: inline-block;
    position: absolute;
    width: 2px;
    height: 50%;
    background: rgb(55, 183, 209);
    left: 2%;
  }
  .inuputt:not(:placeholder-shown) + .label::after {
    content: '';
    display: inline-block;
    position: absolute;
    width: 2px;
    height: 50%;
    background: rgb(55, 183, 209);
    right: 2%;
  }
  .inuputt::placeholder {
    color: #000;
    font-size: 0;
  }
</style>
